<?php
require_once "config.php";
    if($_SERVER['REQUEST_METHOD'] == 'POST'){
        $data = array(
            'img_url' => $_POST['img_url'],
            'desc' => $_POST['desc'],
            'title' => $_POST['title'],
            'id' => $_POST['id'],
            'u_id' => $_POST['u_id'],
            'link' => $_POST['link'],
            'time' => time(),
        );
        if(empty($data['img_url']) || empty($data['desc']) || empty($data['title'])){
            $result['status'] = 'n';
            $result['info'] = '图片，描述，标题不能为空';
            exit(json_encode($result));
        }
        // $type = $_POST['type'];
        $share_sql = $mysql->query("select * from dyspw_share where u_id = {$data['u_id']} and web_id = {$data['id']}");
        $share = $share_sql->fetch_all(MYSQLI_ASSOC);//分享信息获取
        if(!empty($share)){
            $share_ins = $mysql->query("UPDATE dyspw_share SET img_url='{$data['img_url']}', `desc`='{$data['desc']}', `title`='{$data['title']}', `time`='{$data['time']}' where u_id = {$data['u_id']} and web_id = {$data['id']}");
        }else{
            $share_ins = $mysql->query("insert into dyspw_share (img_url,`desc`,title,web_id,u_id, time,link) values ('{$data['img_url']}','{$data['desc']}','{$data['title']}','{$data['id']}','{$data['u_id']}','{$data['time']}','{$data['link']}')");
        }
        if($share_ins){
            $result['status'] = 'y';
            $result['info'] = '提交分享成功';
            exit(json_encode($result));
        }else{
            $result['status'] = 'n';
            $result['info'] = '提交分享失败，请重新提交';
            exit(json_encode($result));
        }
    }
 ?>
